package com.hiwhitley.easy.day28;

/**
 * Created by hiwhitley on 2016/11/2.
 */
public class AddStrings_415 {
    public String addStrings(String num1, String num2) {
        StringBuilder result = new StringBuilder();
        int maxLength = Math.max(num1.length(), num2.length());
        int carry = 0;
        for(int i=1; i<=maxLength; i++){
            int val = carry;
            if(i<=num1.length()) val += num1.charAt(num1.length()-i)-'0';
            if(i<=num2.length()) val += num2.charAt(num2.length()-i)-'0';
            result.append(val%10);
            carry = val/10;
        }
        if(carry>0)
            result.append(carry);
        return result.reverse().toString();
    }
}
